from __future__ import division

import math
import random
import pygame

def interp(a, b, d):
    x1, y1 = a
    x2, y2 = b
    
    return x1+(x2-x1)*d, y1+(y2-y1)*d
    
    """dist = d * math.sqrt((x1 - x2)**2 + (y1 - y2)**2)
    
    angle = math.atan2(y2 - y1, x2 - x1)
    
    x = math.cos(angle)*dist
    y = math.sin(angle)*dist
    
    return (x+x1, y+y1)"""

class Creep(object):
    def __init__(self, pathing, start, game):
        self.position = start.position
        
        self.pathing = pathing
        
        self.current = start
        self.next = self.pathing[start] 
        
        self.active = True
        
        ###
        
        c = random.randint(128, 255)
        
        self.colour = (c, c, c)
        self.progress = random.randint(0, 24)
        self.game = game
        
        self.health = 100
    
    def update(self):
        self.progress += 1
        
        self.position = interp(self.current.position, self.next.position, self.progress / 25)
        
        if self.health <= 0:
            self.active = False
            self.game.creeps.remove(self)
            self.game._remove_creep(self)
        
        if self.progress >= 25:
            self.progress = 0
            
            prev = self.current
            
            self.current = self.next
            self.next = self.pathing[self.current]
            
            self.game._creep_position(self, self.current)
